/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package co.edu.unal.bioingenium.kbmed.text.filter2;

import co.edu.unal.bioingenium.kbmed.config.Configuration;
import java.io.BufferedReader;
import java.io.FileReader;
import java.util.HashSet;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author Alejandro Riveros Cruz
 */
public class StopWordsFilter implements Filter {

    /**
     *
     */
    private Set<StringBuilder> stopWords;

    /**
     * 
     */
    @Override
    public void init() {
        stopWords = new HashSet<StringBuilder>();
        BufferedReader bufferedReader;
        try {
            bufferedReader = new BufferedReader(new FileReader(Configuration.DATA_DIR));
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                stopWords.add(new StringBuilder(line));
            }
            bufferedReader.close();
        } catch (java.io.FileNotFoundException fnfe) {
            Logger.getLogger(StopWordsFilter.class.getName()).log(Level.WARNING, "The file of stopWords \"" + Configuration.DATA_DIR + "\" don't exist", fnfe);
        } catch (java.io.IOException ioe) {
            Logger.getLogger(StopWordsFilter.class.getName()).log(Level.WARNING, "Error reading stopWords file", ioe);
        }
    }

    /**
     * 
     * @param sb
     * @return
     */
    @Override
    public StringBuilder doFilter(StringBuilder sb) {
        if (!stopWords.contains(sb)) {
            return new StringBuilder("");
        }
        return sb;
    }
}
